package me.younian.transmit;

import java.net.ServerSocket;


public class SocketServerUser implements Runnable {

    private ServerSocket socket = null;

    public void oneServer() {
        try {
            try {
                socket = new ServerSocket(8888);
                //b)指定绑定的端口，并监听此端口。
                System.out.println("2-User服务器启动成功");
                //创建一个ServerSocket在端口5209监听客户请求
            } catch (Exception e) {
                System.out.println("没有启动监听：" + e);
                //出错，打印出错信息
            }
            try {
                //socket.accept();
                //2、调用accept()方法开始监听，等待客户端的连接
                //使用accept()阻塞等待客户请求，有客户
                //请求到来则产生一个Socket对象，并继续执行
            } catch (Exception e) {
                System.out.println("Error." + e);
                //出错，打印出错信息
            }

        } catch (Exception e) {//出错，打印出错信息
            System.out.println("Error." + e);
        }
    }

    @Override
    public void run() {
        oneServer();
    }

    public ServerSocket getSocket() {
        return socket;
    }

    public void setSocket(ServerSocket socket) {
        this.socket = socket;
    }
}
